<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>route</title>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <style>
        img{max-width: 650px;}
    </style>
</head>
<body class="container">
<h1>路由</h1>
<div class="well">
    <h4>新建server.js文件，创建一个服务</h4>
    <xmp>
        var http=require('http');
        var url=require('url');
        function start() {
        function onRequest(request, response) {
        var pathname = url.parse(request.url).pathname;
        console.log("Request for " + pathname + " received.");
        response.writeHead(200, {"Content-Type": "text/plain"});
        response.write("Hello World");
        response.end();
        }

        http.createServer(onRequest).listen(8888);
        console.log("Server has started.");
        }
        exports.start = start;
    </xmp>
    <h4>新建一个app.js，引用server模块启动服务</h4>
    <xmp>
        var server=require('./server');
        server.start();
    </xmp>
</div>
</body>
</html>